/**
 * Created with IntelliJ IDEA.
 * Description:给类对象上锁
 * User: lenovo
 * Date: 2022-09-24
 * Time: 15:08
 */
public class Demo5 {
    static class Counter{
        public int count;
        public void increase(){
            synchronized (Counter.class){//类对象
                count++;
            }

        }
    }
    public static void main(String[] args) {
        Counter counter1 = new Counter();
        Thread t = new Thread(){
            @Override
            public void run() {
                counter1.increase();
            }
        };

        Counter counter2 = new Counter();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                counter2.increase();
            }
        };
    }
}
